<?php
/**
 *  =============================
 * 	后台父类
 * 	=============================
 *	Author: 褚天恩
 *  Date: 2017-10-09
 * @author Administrator
 *
 */
namespace app\walletyhbbadmin\controller;
use Think\Db;
class Kefu extends AdminBase{
	//空操作
	public function _initialize(){
		parent::_initialize();
	}
    /**
     * 客服列表
     */
   	public function index(){
       $list = DB::name('kefu')->where('type','kefu')->select();
       $this->assign('info',$list);
       return $this->fetch('kefu/index');
    }

	//删除客服
	public function del(){
		$where['id'] = input('id');
		$bool = DB::name('kefu')->where($where)->delete();
		if($bool){
			$this->success('删除成功','/walletyhbbadmin/kefu/index');
		}else{
			$this->error('删除失败','/walletyhbbadmin/kefu/index');
		}
	}

	//添加客服
	public function add(){
		return $this->fetch('/kefu/details');
	}

	//执行添加
	public function doadd(){
		$arr['phone']=input('phone');
		$arr['type']='kefu';
		$bool = DB::name('kefu')->insert($arr);
		if($bool){
			$this->success('添加成功','/walletyhbbadmin/kefu/index');
		}else{
			$this->error('添加失败','/walletyhbbadmin/kefu/add');
		}
	}

	//修改客服页面
	public function edit(){
		$where['id']=input('id');
		$kefu = DB::name('kefu')->where($where)->find();
		$this->assign('kefu',$kefu);
		return $this->fetch('kefu/edit');
	}

	//执行修改
	public function doedit(){
		$where['id']=input('id');
		$data['phone']=input('phone');
		$res = DB::name('kefu')->where($where)->update($data);
		if($res){
			$this->success('修改成功','/walletyhbbadmin/kefu/index');
		}else{
			$this->success('修改失败','/walletyhbbadmin/kefu/index');

		}
	}



	//官方邮箱设置
    public function mail(){
        $info = DB::name('config')->where('name','mail')->select();
//        dump($info);
        $this->assign('info',$info);
        return $this->fetch('mail/index');
    }
    public function updateMail()
    {
        $data['value'] = input('value');
        $data['desc'] = input('desc');
//        dump($data['value']);
//        dump($data['desc']);
        $res = DB::name('Config')->where('name',mail)->update($data);

            $this->success('操作成功');

    }

    //添加邮箱
    public function mailadd(){
   	    return $this->fetch('mail/details');
    }

    //添加
    public function maildoadd(){
        $arr['phone']=input('phone');
        $arr['type']='mail';
        $bool = DB::name('kefu')->insert($arr);
        if($bool){
            $this->success('添加成功','/walletyhbbadmin/kefu/mail');
        }else{
            $this->error('添加失败','/walletyhbbadmin/kefu/mailadd');
        }
    }

    //修改
    public function mailedit(){
        $where['id']=input('id');
        $kefu = DB::name('kefu')->where($where)->find();
        $this->assign('kefu',$kefu);
        return $this->fetch('mail/edit');
    }

    //删除
    public function maildel(){
        $where['id'] = input('id');
        $bool = DB::name('kefu')->where($where)->delete();
        if($bool){
            $this->success('删除成功','/walletyhbbadmin/kefu/index');
        }else{
            $this->error('删除失败','/walletyhbbadmin/kefu/index');
        }
    }

    //执行修改
    public function maildoedit()
    {
        $where['id'] = input('id');
        $data['phone'] = input('phone');
        $res = DB::name('kefu')->where($where)->update($data);
        if ($res) {
            $this->success('修改成功', '/walletyhbbadmin/kefu/mail');
        } else {
            $this->success('修改失败', '/walletyhbbadmin/kefu/mail');

        }
    }
}